/*
 * CreateOrUpdateAction.java
 *
 * Created on 29 marzec 2007, 23:01
 *
 */

package arocms.news;

import arocms.business.News;
import arocms.business.NewsDAO;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author arek
 */
public class CreateOrUpdateAction extends Action{
    
    /** Creates a new instance of CreateOrUpdateAction */
    public CreateOrUpdateAction() {
        
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        NewsFormBean nf = (NewsFormBean) form;
        News news = new News();
        Long pk = null;
        try {
            pk = new Long(nf.getId());
            news.setId(pk);
        } catch (Exception ex) {
        
        }
        news.setCreation_date(new Date());
        news.setDescription(nf.getDescription());
        news.setTitle(nf.getTitle());
        news.setHeading(nf.getHeading());
        new NewsDAO().createOrUpdate(news);
        return mapping.findForward("success");
    }
}
